﻿#include<iostream>
using namespace std;

int ans[10000], back[40], mid[40];

void solve(int p1, int p2, int q1, int q2, int pos)
{
	if (p1 > p2 || q1 > q2)return;
	int p = q1;
	while (mid[p] != back[p2])p++;
	ans[pos] = mid[p];
	solve(p1, p1 + (p - q1) - 1, q1, p - 1, pos << 1);
	solve(p1 + (p - q1), p2 - 1, p + 1, q2, pos << 1 | 1);
}

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> back[i];
	}
	for (int i = 0; i < n; i++)
	{
		cin >> mid[i];
	}
	solve(0, n - 1, 0, n - 1, 1);
	int flag = 0;
	for (int i = 1; i < 10000; i++)
	{
		if (ans[i])
		{
			if (flag)cout << " ";
			cout << ans[i];
			flag = 1;
		}
	}
	return 0;
}